package cn.kgc.househou.controller;

import cn.kgc.househou.pojo.Houseinfo;
import cn.kgc.househou.pojo.ResultEntity;
import cn.kgc.househou.service.HousetypeinfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@CrossOrigin
@RestController
@Api(tags = "房屋信息表",description = "提供用户相关的Rest API")
public class HouseInfoController {

    @Resource
    HousetypeinfoService housetypeinfoService;

    @GetMapping("/selectHouseInfo")
    @ApiOperation("动态查询用户并分页")
    @ApiImplicitParam(name = "pageNum",value = "页码",required = false)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "用户id"),
            @ApiImplicitParam(name = "name",value = "用户名"),
            @ApiImplicitParam(name = "pageIndex",value = "页码",required = false),
            @ApiImplicitParam(name = "pageSize",value = "页面行数",required = false),
    })
    public ResultEntity<PageInfo<Houseinfo>> sele(@RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum){
        PageInfo<Houseinfo> sele = housetypeinfoService.sele(pageNum);
    return ResultEntity.successWithoutData(sele);
    }

    @PostMapping("/insetHouseInfo")
    @ApiOperation("添加房屋信息")
    @ApiImplicitParams({
          @ApiImplicitParam(name = "housedesc",value = "房屋描述",required = true),
          @ApiImplicitParam(name = "typeid",value = "房屋户型",required = true),
          @ApiImplicitParam(name = "monthrent",value = "租金",required = true)
    })

    public Map<String,String> insert(@RequestBody Houseinfo houseinfo){
        Map<String,String> map=new HashMap<>();
        Integer integer = housetypeinfoService.addHouseInfo(houseinfo);
        if(integer>0){
            map.put("msg","添加成功!");
        }else {
            map.put("msg","添加失败!");
        }
        return map;
    }
}
